<?php
class Application_Form_Team extends Zend_Form
{
	protected $_type;
	public function __construct($type=null){		
		$this->_type = $type;
		parent::__construct();
	}
	
    public function init()
    {
    	$this->setEnctype(Zend_Form::ENCTYPE_MULTIPART);
    	$this->setMethod('post');
    	$title = new Zend_Form_Element_Text('title');
    	$title->setLabel('Title')
        		->setOptions(array('size' => 25))
        		->setRequired(true)
        		->addFilter('StripTags')
        		->addFilter('StringTrim')
        		->addValidator('Alnum', false, array('allowWhiteSpace' => true))		
        		->addValidator('Db_NoRecordExists', false, array('table' => 'team', 'field' => 'title'));       	
        $title->getValidator('Db_NoRecordExists')->setMessage('This title already exists', Zend_Validate_Db_NoRecordExists::ERROR_RECORD_FOUND);

		$descr = new Zend_Form_Element_Textarea('descr');
	    $descr->setLabel('Description')
	       		->setOptions(array('rows' => 3, 'cols' => 25))
	       		->addFilter('StripTags')
	       		->addFilter('StringTrim');        
        
    	/*$logo = new Zend_Form_Element_Text('logo');
    	$logo->setLabel('Logo')
        		->setOptions(array('size' => 25))
        		->setRequired(true)
        		->addFilter('StripTags')
        		->addFilter('StringTrim');*/
        		//-> Try validator file exists
        		
        $visible = new Zend_Form_Element_Checkbox('visible');
	    $visible->setLabel('Visible')
	       		->setRequired(true)
	       		->addValidator('Int');
	       		
	    $logo = new Zend_Form_Element_File('logo');
		$logo->setLabel('Upload logo:')		      
		      ->setRequired(true)
		      ->setMaxFileSize(102400)
		      ->setValueDisabled(true); 
		$logo->addValidator('Size', false, 102400);            // limit to 10 meg
		$logo->addValidator('Extension', false, 'jpg,jpeg,png,gif');// only JPEG, PNG, and GIFs	      
	    
		$submit = new Zend_Form_Element_Submit('submit');
	    $submit->setLabel('Add');
	    if($this->_type == 'edit'){
	    	$logo->setRequired(false);
	    	$submit->setLabel('Edit');
	    }
		$this->addElements(array($title, $descr, $logo, $visible, $logo, $submit));
    }
	public  function excludeFrom($element, $validator, $field, $value){
    	$this->$element->getValidator($validator)->setExclude(array('field'=>$field, 'value'=> $value));
    }
}